package fr.emse.tatiana.commands;


import org.eclipse.jface.action.Action;
import org.eclipse.core.resources.*;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.wizards.newresource.BasicNewFolderResourceWizard;
import fr.emse.tatiana.CorpusNavigationView;


public class CreateFolderAction extends Action{
	private final IWorkbenchWindow window;
	private final String navigationId;

	private static CreateFolderAction instance;

	public static CreateFolderAction getInstance() {
		return instance;
	}

	public CreateFolderAction(IWorkbenchWindow window, String label, String navigationId) {
		this.window = window;
		this.navigationId = navigationId;
		setText(label);
		setId(ICommandIds.CMD_CREATE_FOLDER);
		setImageDescriptor(fr.emse.tatiana.Activator.getImageDescriptor("/icons/sample2.gif"));
		this.setEnabled(false);
		instance = this;
	}


	@Override
	public void run() {
		if(window != null) {	
			BasicNewFolderResourceWizard wizard = new BasicNewFolderResourceWizard();
			wizard.init(window.getWorkbench(),((CorpusNavigationView) window.getActivePage().findView(this.navigationId)).getSelection());
			WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
			dialog.open();
		}	
	}
}